package com.way.note;

import android.app.Activity;
import android.content.Context;
import android.text.InputFilter;
import android.text.Spanned;
import android.widget.Toast;

import com.way.note.data.NoteDataManager;

public class BaseActivity extends Activity {

	public NoteDataManager getDataManager(Context context) {
		return ((NoteApplication) getApplication()).getNoteDataManager(context);
	}

	public class ToastLenFilter implements InputFilter {
		Toast toast = null;
		int mMax;

		public ToastLenFilter(int max) {
			this.mMax = max;
		}

		public CharSequence filter(CharSequence source, int start, int end,
				Spanned dest, int dstart, int dend) {
			if (end - start + dest.length() > mMax) {
				if (toast == null) {
					String toastMessage = BaseActivity.this.getString(
							R.string.tilte_input_more, mMax);
					toast = Toast.makeText(BaseActivity.this, toastMessage,
							Toast.LENGTH_LONG);
				}
				toast.show();
			}
			return null;
		}
	}

}
